package client;


import java.util.Hashtable;

import javax.naming.Context;

public class ClientTools {
	
	private ClientTools() {
		super();
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Hashtable giveMeJndiProperties() {
		final Hashtable jndiProperties = new Hashtable();
		jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
		jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
		jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");
		jndiProperties.put("jboss.naming.client.ejb.context", true);
		jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
		return jndiProperties;
	}

	public static String giveMeTheRemoteNameOfMyEjb(String projectName,Class<?> EjbImplClass, Class<?> EjbRemoteClass, boolean isStateFull) {
		final String appName = "";
        // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
        // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
        // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
        // jboss-as-ejb-remote-app
        final String moduleName = projectName;
        // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
        // our EJB deployment, so this is an empty string
        final String distinctName = "";
        // The EJB name which by default is the simple class name of the bean implementation class
        final String beanName = EjbImplClass.getSimpleName();
        // the remote view fully qualified class name
        final String viewClassName = EjbRemoteClass.getName();
        // let's do the lookup
        
		System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
		return "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName+((isStateFull)?"?stateful":"");
		
	
		
	}
}
